package ar.com.photo_admin.domain

import java.util.List;
import java.util.Set;

class EventAlbum {

    String name
	
	String description;

	Event event
	
	List photoInAlbums
	
	EventPhoto coverPhoto;

	static belongsTo = [Event]
		
	static hasMany = [photoInAlbums : PhotoInAlbum]

	static constraints = {
		name(blank:false)
		description(nullable:true,blank:true)
		event(nullable:false)
		coverPhoto(nullable:true)
	}
	
	static mapping = {
		coverPhoto column: 'cover_photo__id'
		//albumPhotos cascade: 'none'		
		//albumPhotos joinTable:[name:"mm_album_photo", key:'mm_album_id' ]
	}	
	
	List getAlbumPhotos() {
		return photoInAlbums.collect{it.photo}
	}		
	
	
	List addToAlbumPhotos(EventPhoto photo) {
		PhotoInAlbum.link(photo, this)
		return getAlbumPhotos()
	}
	
	List removeFromAlbumPhotos(EventPhoto photo) {
		PhotoInAlbum.unlink(photo, this)
		return getAlbumPhotos()
	}

}
